matrix = [
    [123, 456, 789],
    [10, 20, 30],
    [1, 2, 3]
]

# 找到每列中最大元素的宽度
column_widths = []
for j in range(len(matrix[0])):
    max_width = len(str(max([matrix[i][j] for i in range(len(matrix))])))
    column_widths.append(max_width)

# 打印上边框
print('+' + '+'.join(['-'*(width + 2) for width in column_widths]) + '+')

# 打印矩阵内容
for row in matrix:
    print('|', end='')
    for j in range(len(row)):
        element = str(row[j])
        padding = column_widths[j] - len(element)
        print(' ' + element + ' '*padding + '|', end='')
    print()

# 打印下边框
print('+' + '+'.join(['-'*(width + 2) for width in column_widths]) + '+')
